<template>
  <div>
    <!-- 按钮 -->

    <el-button style="margin:10px 10px" type="primary" icon="el-icon-refresh-right" circle
      @click="getDynamicExtensionProcessList"></el-button>
    <!-- <el-button type="primary" @click="add()">添加</el-button> -->
    <el-table style="width: 100%;" border :data="list">
      <!-- <el-table-column prop="createId" label="名称" align="center">
        </el-table-column> -->
      <!--   <el-table-column prop="memberLevel" label="会员等级" align="center">
                <template slot-scope="{ row, $index }">
                    <div>{{ row.memberLevel == "1" ? 'vip' : 'svip' }}</div>
                </template>
            </el-table-column> -->
      <el-table-column prop="taskName" label="任务名称" align="center">
      </el-table-column>
      <el-table-column prop="taskType" label="任务类型" align="center">
      </el-table-column>
      <el-table-column prop="giveGold" label="金币" align="center">
      </el-table-column>
      <el-table-column prop="pageName" label="页面名称" align="center">
      </el-table-column>

      <el-table-column label="操作" width="200" align="center">
        <template slot-scope="{ row, $index }">
          <!-- <el-button type="primary" icon="el-icon-edit" circle></el-button> -->
          <el-tooltip content="修改任务信息" placement="top" slot="reference">
            <el-button type="primary" icon="el-icon-edit" @click="ubpateBannar(row)"></el-button>
          </el-tooltip>
          <!--     <el-popconfirm title="是否删除任务？" icon="el-icon-info" icon-color="red" @confirm="getDelete(row.id)">
                        <el-tooltip content="删除任务" placement="top" slot="reference">
                            <el-button type="danger" icon="el-icon-delete"></el-button>
                        </el-tooltip>
                    </el-popconfirm> -->
        </template>
      </el-table-column>
    </el-table>

    <!-- 修改对话框  -->
    <el-dialog title="修改任务信息" :visible.sync="dialogFormVisible">
      <el-form style="width:80%" :model="tmFrom" :rules="rules" ref="ruleForm">
        <!--  <el-form-item label="会员等级" label-width="100px" prop="memberLevel">
                    <div>{{ tmFrom.memberLevel == 1 ? "vip" : "Svip" }}</div>
                </el-form-item> 1新 2日-->
        <el-form-item label="任务类型" label-width="100px" prop="taskType">
          <el-input disabled autocomplete="off" v-model="tmFrom.taskType"></el-input>
        </el-form-item>
        <el-form-item label="任务名称" label-width="100px" prop="taskName">
          <el-input autocomplete="off" v-model="tmFrom.taskName"></el-input>
        </el-form-item>
        <!--      <el-form-item label="页面路径" label-width="100px" prop="frontPageConfigurationId">
          <el-input autocomplete="off" v-model="tmFrom.frontPageConfigurationId"></el-input>
        </el-form-item> -->
        <!--   <el-table-column prop="memberLevel" label="会员等级" align="center">
                  <template slot-scope="{ row, $index }">
                      <div>{{ row.memberLevel == "1" ? 'vip' : 'svip' }}</div>
                  </template>
              </el-table-column> -->
        <el-form-item label="页面名称" label-width="100px"  prop="pageName">
          <el-select v-model="tmFrom.frontPageConfigurationId" >
            <!-- <el-option label="新手任务" value="新手任务"></el-option>
                      <el-option label="每日任务" value="每日任务"></el-option> -->
            <el-option v-for="v in FrontPageUrlConfigurationList" :key="v.id" :value="v.id" :label="v.pageName">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="金币" label-width="100px" prop="giveGold">
          <el-input autocomplete="off" v-model="tmFrom.giveGold"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogFormVisible = false">取 消</el-button>
        <!-- <el-button type="primary" @click="getAddBannerImage" v-if="state">确 定</el-button> -->
        <el-button type="primary" @click="UpdateBillingRules(tmFrom.taskId)">修改</el-button>
      </div>
    </el-dialog>

    <!-- 添加对话框 -->
    <!-- <el-dialog title="添加任务" :visible.sync="dialogFormVisible1">
            <el-form style="width:80%" :model="list1" :rules="rules" ref="ruleForm">
               <el-form-item label="是否自定义">
                    <el-select v-model="list1.memberLevel" placeholder="请选择是否自定义" prop="memberLevel">
                        <el-option label="vip" value="1"></el-option>
                        <el-option label="svip" value="2"></el-option>
                    </el-select>
                </el-form-item>

                <el-form-item label="任务类型">
                    <el-select v-model="list1.taskType" placeholder="请选择是否自定义" prop="taskType">
                        <el-option label="新手任务" value="新手任务"></el-option>
                        <el-option label="每日任务" value="每日任务"></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="任务名称" label-width="100px" prop="taskName">
                    <el-input autocomplete="off" v-model="list1.taskName"></el-input>
                </el-form-item>
                <el-form-item label="金币" label-width="100px" prop="giveGold">
                    <el-input autocomplete="off" v-model="list1.giveGold"></el-input>
                </el-form-item>

            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button @click="dialogFormVisible1 = false">取 消</el-button>
                <el-button type="primary" @click="getAddMemberLevelConfiguration">提交</el-button>
            </div>
        </el-dialog> -->
  </div>
</template>

<script>
  export default {
    name: 'TaskCenter',
    data() {

      return {
        //列表数据
        list: [],
        FrontPageUrlConfigurationList: [],
        list1: {

        },
        // 对话框显示与隐藏控制
        dialogFormVisible: false,
        dialogFormVisible1: false,
        // 表单对象
        tmFrom: {},
        // 当前为修改还是添加 修改为false 添加为true
        state: true,
        // 表单验证
        rules: {
          pageName: [{
            required: true,
            message: '请选择页面名称',
            trigger: 'blur'
          }],
          // proportion: [
          //     { required: true, message: '请选择计费比列，数字和小数', trigger: 'blur' },
          //     {
          //         transform(value) {
          //             return Number(value);
          //         },
          //         validator(rule, value, callback) {
          //             if (Number.isFinite(value) && value > 0) {
          //                 callback();
          //             } else {
          //                 callback(new Error("请输入类型为数字和小数，并不少于0"));
          //             }
          //         },
          //         trigger: "blur",
          //     }
          // ],
          intro: [{
            required: true,
            message: '请选择规则简介',
            trigger: 'blur'
          }]
        }

      }
    },
    mounted() {
      this.getUserTaskList()
      this.getFrontPageUrlConfigurationList()
    },

    methods: {
      // 获取app页面列表
      async getFrontPageUrlConfigurationList() {
        let res = await this.$API.system.getFrontPageUrlConfigurationList()
        console.log(res, "获取app页面列表")
        this.FrontPageUrlConfigurationList = res.data;
      },
      // 获取任务列表
      async getUserTaskList() {
        let res = await this.$API.system.getUserTaskList()
        console.log(res, "111")
        this.list = res.data;
      },

      // 取消
      getShow() {
        this.state = true
        this.dialogFormVisible = true
        this.tmFrom = {
          // name: '',
          // proportion: '',
          // intro: ''
        }
      },

      // add() {
      //     this.dialogFormVisible1 = true
      // },
      // 刷新
      getDynamicExtensionProcessList() {
        this.getUserTaskList()
      },
      // // 添加
      // getAddBannerImage() {
      //     console.log(this.getMemberLevelConfigurationList());
      // },
      // // 添加一条任务
      // getAddMemberLevelConfiguration() {
      //     this.$refs.ruleForm.validate(async (valid) => {
      //         if (valid) {
      //           console.log(this.list1)
      //             // let res = await this.$API.system.addUserTask(this.list1);
      //             // this.dialogFormVisible1 = false;
      //             // this.getUserTaskList()
      //         } else {
      //             console.log('error submit!!');
      //             return false;
      //         }
      //     })
      // },

      // 点击修改
      ubpateBannar(row) {
        this.state = false
        this.dialogFormVisible = true;
        // 浅拷贝  让tmFrom收到的数据非服务器直接传回的数据
        this.tmFrom = {
          ...row
        };
      },
      // 点击修改
      UpdateBillingRules(taskId) {
        this.$refs.ruleForm.validate(async (valid) => {
          if (valid) {
            if (this.tmFrom.taskType == '新手任务') {
              this.tmFrom.taskType = 1
            } else {
              this.tmFrom.taskType = 2
            }
            this.tmFrom.id = taskId
            console.log(this.tmFrom,taskId)
            let res = await this.$API.system.updateUserTask(this.tmFrom);
            this.dialogFormVisible = false;
            this.getUserTaskList()
          } else {
            console.log('error submit!!');
            return false;
          }
        })
      },
      // // 删除
      // async getDelete(id) {
      //     let res = await this.$API.system.getDeleteMemberLevelConfiguration({ id: id });
      //     this.getMemberLevelConfigurationList()

      // }
    }
  }
</script>

<style lang="scss">
  .avatar-uploader .el-upload {
    border: 1px dashed #d9d9d9;
    border-radius: 6px;
    cursor: pointer;
    position: relative;
    overflow: hidden;
  }

  .avatar-uploader .el-upload:hover {
    border-color: #409EFF;
  }

  .avatar-uploader-icon {
    font-size: 28px;
    color: #8c939d;
    width: 178px;
    height: 178px;
    line-height: 178px;
    text-align: center;
  }

  .avatar {
    width: 178px;
    height: 178px;
    display: block;
  }
</style>
